package fr.xgouchet.wedding.client.view;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

import fr.xgouchet.wedding.client.presenter.FeedbackMessagePresenter;

/**
 * UI Widget used to display a FeedbackMessage.
 * 
 * @author x.gouchet
 * 
 */
public class FeedbackMessageView extends Composite implements
		FeedbackMessagePresenter.Display {

	/**
	 * Default Constructor
	 */
	public FeedbackMessageView() {
		// Main panel
		SimplePanel main = new SimplePanel();
		initWidget(main);
		main.addStyleName("message");

		// Create the text content
		mMessage = new Label();

		// final assembly
		main.add(mMessage);
	}

	/**
	 * @see FeedbackMessagePresenter.Display#setData(String)
	 */
	public void setData(String data) {
		mMessage.setText(data);
	}

	/**
	 * @see FeedbackMessagePresenter.Display#setError(boolean)
	 */
	public void setError(boolean error) {
		if (error)
			mMessage.addStyleName("error");
	}

	/**
	 * @see FeedbackMessagePresenter.Display#asWidget()
	 */
	public Widget asWidget() {
		return this;
	}

	/** the message to display */
	private final Label mMessage;
}
